package com.njwb.day09.exception;

public class Person {


    private String name ;
    private int age ;

    private String sex ;

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) throws SexException {

        if("男".equals(sex) || "女".equals(sex)) {
            this.sex = sex;
        }else{
            throw new SexException("性别错误");
        }



    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException  {
        if(age<1) {
            //自行抛出一个异常对象
            throw new AgeException("年龄不合法");

        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age + '\'' +
                ", sex=" + sex + '\'' +
                '}';
    }
}
